package com.lenovo.test

/**
  * Created by root on 7/29/17.
  */
object last_mag {


  def main(args: Array[String]): Unit = {

    val u1= new User;
    val u2= new User;
    val u3= new User;
    val u4= new User;
    val u5= new User;
    val u6= new User;
    val u7= new User;

    u1.setEmployee_id("1")
    u1.setManager_id("2")

    u2.setEmployee_id("2")
    u2.setManager_id("3")

    u3.setEmployee_id("3")
    u3.setManager_id("4")

    u4.setEmployee_id("4")
    u4.setManager_id("5")

    u5.setEmployee_id("5")
    u5.setManager_id("6")

    u6.setEmployee_id("6")
    u6.setManager_id("7")

    u7.setEmployee_id("7")
    u7.setManager_id("8")


  println(  last_mag(u1,List(u2,u3,u4,u5,u6,u7),List(8.toString)) )

  }
  def last_mag(user: User,all_user:List[User],last_id:List[String]):User={
    if (last_id.contains(user.getManager_id) ){

      all_user.foreach(row => {
        if (user.getManager_id == row.getEmployee_id){
          user.setManager_id(row.getEmployee_id)
        }else{

        }})


      last_mag(user,all_user,last_id)
    }else{
      return user
    }
  }

}
